package operation;

import book.Book;
import book.BookList;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-07
 * Time: 16:49
 */
public class AddOperation implements IOperation{

    public void work(BookList bookList) {
        System.out.println("新增图书");
        System.out.println("请输入书名");
        String bookname = scanner.nextLine();
        System.out.println("请输入作者");
        String bookauthor = scanner.nextLine();
        System.out.println("请输入类型");
        String booktype = scanner.nextLine();
        System.out.println("请输入定价");
        int bookprice = scanner.nextInt();
        Book book = new Book(bookname, bookauthor, bookprice, booktype);
        Book[] books = bookList.getBooks();
        int size = bookList.getUedSize();
        if (size >= bookList.getBooks().length) {
            books = Arrays.copyOf(bookList.getBooks(), bookList.getBooks().length * 2);
            bookList.setBooks(books);
        }
        bookList.setBook(size,book);
        bookList.setUedSize(size + 1);
        System.out.println("新增图书成功");
      }
    }

